﻿
@{
    Layout = null;
}

<div>
    <div class="input-group">
        <div class="col-3 pr-0" style="display: none">
            <label id="SAMPLE-AddSpecCollectionAnalyte-CollectionId">@ViewData["CollectionId"]</label> @*这个ID就是指标集的ID*@
            <label id="SAMPLE-AddSpecCollectionAnalyte-Parent-ModalID">@ViewData["ModalID"]</label>
        </div>
    </div>
    <div class="col-3 pr-0" style="display: none">
        <label id="SAMPLE-AddSpecCollectionAnalyte-SpecId">@ViewData["SpecId"]</label>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0 pl-0">
            <span class="input-group-text font-rfs-modal border-radius-noright noRightBorder">分类</span>
        </div>
        <div class="col-9 pl-0">
            <select id="SAMPLE-AddSpecCollectionAnalyte-Classification" class="form-control font-rfs-modal border-radius-noleft"></select>
        </div>
    </div>
</div>
<div class="table-responsive-sm modal-table-shadow p-0 bg-white rounded col-md-12 pre-scrollable" style="height: 60vh;">
    <table id="SAMPLE-AddSpecCollectionAnalyte-AnalyteList" class="table table-striped table-bordered-modal table-sm table-hover">
        <thead>
            <tr>
                <th>ID</th>
                <th>代码</th>
                <th>名称</th>
                <th>描述</th>
                <th>默认指标</th>
            </tr>
        </thead>
        <tbody style="font-size: calc(0.6em + 0.1vw) !important"></tbody>
    </table>
</div>
<div class="text-right" style="padding-top: 5px;">
    <button id="SAMPLE-AddSpecCollectionAnalyte-confirm" type="button" class="btn btn-primary font-rfs-modal" disabled="disabled">确定</button>
    <button id="SAMPLE-AddSpecCollectionAnalyte-cancel" type="button" class="btn btn-info font-rfs-modal">取消</button>
</div>

<script>
    var SAMPLE_AddSpecRelationAnalyte_AnalyteId = "";

    $(document).ready(function () {
        LoadClassification();
    });

    function LoadClassification() {
        /*页面加载时，加载 分类 信息*/
        $.post("GetAnalyteClassification", {
            //Type: type  // 传递的参数，对应控制器里的参数
        }, function (data) {
            for (var i = 0; i < data.length; i++) {
                $("#SAMPLE-AddSpecCollectionAnalyte-Classification").append(new Option(data[i].classification));
            }
            $("#SAMPLE-AddSpecCollectionAnalyte-Classification").prepend(new Option("", ""));
            $("#SAMPLE-AddSpecCollectionAnalyte-Classification").val("");
        });
    }

    $("#SAMPLE-AddSpecCollectionAnalyte-Classification").change(function () {

        $("#SAMPLE-AddSpecCollectionAnalyte-confirm").attr("disabled", true);

        var columns = [{ field: "id", visible: false }, { field: "code" }, { field: "name" }, { field: "description" }, { field: "defaultSpecName" }];
        SAMPLE_AddSpecRelationAnalyte_AnalyteId = "";
        $('#SAMPLE-AddSpecCollectionAnalyte-AnalyteList').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
        $('#SAMPLE-AddSpecCollectionAnalyte-AnalyteList').bootstrapTable({
            method: 'post',
            url: "GetAnalyteListByClassification",
            dataType: "json",  // 服务器端返回值类型
            contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
            queryParams: function (params) {
                var data = {
                    Classification: $("#SAMPLE-AddSpecCollectionAnalyte-Classification").find("option:selected").text(),  // 传递的参数，这的名称要和控制器里对应的参数名称一样
                };
                return data;
            }, //参数
            queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

            uniqueId: "id",          // 设置主键
            locale: "zh-CN",
            columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。
            onClickRow: function (row, $element, field) {
                $("#SAMPLE-AddSpecCollectionAnalyte-AnalyteList").find("tbody").find("tr").each(function () {
                    $(this).removeClass('changeblueColor');
                });
                $element.addClass("changeblueColor");
                SAMPLE_AddSpecRelationAnalyte_AnalyteId = row.id;
                $("#SAMPLE-AddSpecCollectionAnalyte-confirm").attr("disabled", false);
            },
            silent: true,  //刷新事件必须设置
            formatLoadingMessage: function () {
                return "请稍等，正在加载中...";
            },
            formatNoMatches: function () {  //没有匹配的结果
                return '无符合条件的记录';
            },
            onLoadError: function (data) {
                $('#SAMPLE-AddSpecCollectionAnalyte-AnalyteList').bootstrapTable('removeAll');
            },
            onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                $('.fixed-table-toolbar').css("height", "0px"); /* 隐藏表格上的工具栏 */
            },
            formatShowingRows: function (pageFrom, pageTo, totalRows) {
                return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
            },
            formatRecordsPerPage: function (pageNumber) {
                return " 每页显示" + pageNumber + '条记录';
            }
        });

    });

    $("#SAMPLE-AddSpecCollectionAnalyte-cancel").click(function (event) {
        var modalID = $("#SAMPLE-AddSpecCollectionAnalyte-Parent-ModalID").html();
        $("#" + modalID).modal('hide');
    });

    $("#SAMPLE-AddSpecCollectionAnalyte-confirm").click(function () {
        var jsonStr = {};
        jsonStr["CollectionId"] = $("#SAMPLE-AddSpecCollectionAnalyte-CollectionId").html();
        jsonStr["AnalyteId"] = SAMPLE_AddSpecRelationAnalyte_AnalyteId;

        $.post("AddSpecCollectionAanylte", {
            jsonStr: JSON.stringify(jsonStr)
        }, function (data) {
            if (data.indexOf("成功") >= 0) {
                $("#SAMPLE-AddSpecCollectionAnalyte-cancel").click();
            } else {
                alert(data);
            }
        });
    });

</script>
